package com.higgins.server.projectmanagement.datamodel;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.GenericGenerator;
import com.higgins.client.agentapp.datamodel.AgentDTO;
import com.higgins.client.agentapp.datamodel.JobSiteDTO;
import com.higgins.client.dataModel.CoveringLetterDTO;
import com.higgins.client.dataModel.StrategyDTO;
import com.higgins.client.projectmanagement.ProjectItemDTO;
import com.higgins.server.agentapp.datamodel.Agency;

@Entity
@Table(name = "projectItem")
public class ProjectItem {
    @Id
    @GeneratedValue(generator = "increment")
    @GenericGenerator(name = "increment", strategy = "increment")
	private Long id;
	private Long parentId;
	private Integer priority;
	private String task;
	private Double forecast;
	private Double actual;
	private Double complete;
	private Boolean permanent;
	private Boolean immediate;
	private Boolean followUp;
	private Date followUpDate;
	private String followUpDateString;
	private Date startTimestamp;
	private Date endTimestamp;
//	private List<Long> children = new ArrayList<Long>();    
    
    public ProjectItem() {
        // This is used by JPA
    }
 
	public void setId(Long id)	{
		this.id = id;
	}
	public Long getId()	{
		return id;
	}
	public void setParentId(Long parentId)	{
		this.parentId = parentId;
	}
	public Long getParentId()	{
		return parentId;
	}
	public void setPriority(Integer priority)	{
		this.priority = priority;
	}
	public Integer getPriority()	{
		return priority;
	}
	public void setTask(String task)	{
		this.task = task;
	}
	public String getTask()	{
		return task;
	}
	public void setForecast(Double forecast)	{
		this.forecast = forecast;
	}
	public Double getForecast()	{
		return forecast!=null?forecast:0.0;
	}
	public void setActual(Double actual)	{
		this.actual = actual;
	}
	public Double getActual()	{
		return actual!=null?actual:0.0;
	}
	public Double getComplete()	{
		return complete;
	}
	public void setComplete(Double complete)	{
		this.complete = complete;
	}
	public Boolean getPermanent()	{
		return permanent;
	}
	public void setPermanent(Boolean permanent)	{
		this.permanent = permanent;
	}
	public Boolean getImmediate()	{
		return immediate;
	}
	public void setImmediate(Boolean immediate)	{
		this.immediate = immediate;
	}
	public Boolean getFollowUp()	{
		return followUp;
	}
	public void setFollowUp(Boolean followUp)	{
		this.followUp = followUp;
	}
	public Date getFollowUpDate()	{
		return followUpDate;
	}
	public void setFollowUpDate(Date followUpDate)	{
		this.followUpDate = followUpDate;
	}
	public String getFollowUpDateString()	{
		return followUpDateString;
	}
	public void setFollowUpDateString(String followUpDateString)	{
		this.followUpDateString = followUpDateString;
	}	
	public Date getStartTimestamp()	{
		return startTimestamp;
	}
	public void setStartTimestamp(Date startTimestamp)	{
		this.startTimestamp = startTimestamp;
	}
	public Date getEndTimestamp()	{
		return endTimestamp;
	}
	public void setEndTimestamp(Date endTimestamp)	{
		this.endTimestamp = endTimestamp;
	}
//	public void addChild(Long id)	{
//		children.add(id);
//	}
//	public void setChildren(List<Long> children)	{
//		this.children = children;
//	}
//	public List<Long> getChildren()	{
//		return children;
//	}

    public ProjectItemDTO toDTO()	{
    	ProjectItemDTO dto = new ProjectItemDTO();
    	dto.setId(id);
    	dto.setParentId(parentId);
    	dto.setPriority(priority);
    	dto.setTask(task);
    	dto.setForecast(forecast);
    	dto.setActual(actual);
    	dto.setComplete(complete);
    	dto.setPermanent(permanent);
    	dto.setImmediate(immediate);
    	dto.setFollowUp(followUp);
    	dto.setFollowUpDate(followUpDate);
    	dto.setFollowUpDateString(followUpDateString);
    	dto.setStartTimestamp(startTimestamp);
    	dto.setEndTimestamp(endTimestamp);
    	return dto;
    }
    public void update(ProjectItemDTO dto)	{
    	this.parentId = dto.getParentId();
    	this.priority = dto.getPriority() != null? dto.getPriority() : 1;
    	this.task = dto.getTask() !=null ? dto.getTask() : "";
    	this.forecast = dto.getForecast() !=null ?  dto.getForecast():0.0;
    	this.actual = dto.getActual() !=null ? dto.getActual() : 0.0;
    	this.complete = dto.getComplete() !=null ? dto.getComplete() : 0.0;
    	this.permanent = dto.getPermanent() !=null ? dto.getPermanent() : false;
    	this.immediate = dto.getImmediate() !=null ? dto.getImmediate() : false;
    	this.followUp = dto.getFollowUp() !=null ? dto.getFollowUp() : false;
    	this.followUpDate = dto.getFollowUpDate();
    	this.followUpDateString = dto.getFollowUpDateString();
    	this.startTimestamp = dto.getStartTimestamp();
    	this.endTimestamp = dto.getEndTimestamp();
    }
}